
//
//  QSShareManager.m
//  好脉
//
//  Created by 郭凯 on 2018/8/14.
//  Copyright © 2018年 yeqingyu. All rights reserved.
//

#import "QSShareManager.h"
#import <UShareUI/UShareUI.h>
#import <UMCommon/UMCommon.h>
@implementation QSShareManager
    
+ (void)configUSharePlatforms{
    [UMConfigure initWithAppkey:@"5b19e357f29d98343d000045" channel:@"App Store"];
    [UMSocialGlobal shareInstance].isUsingHttpsWhenShareContent = NO;
    /* 设置微信的appKey和appSecret */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"wx37e2712d6e92136e" appSecret:@"4fa8da2815e3cb8439871da14c6c22f8" redirectURL:@"http://app.haomaijiankang.com/"];
    /*设置QQ平台的appID*/
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:@"101520384"  appSecret:@"f225d3b7dfd46c4ec3427350a5e3cad8" redirectURL:@"http://app.haomaijiankang.com/"];
    /* 设置新浪的appKey和appSecret */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:@"2907337375"  appSecret:@"e3660195056afd87d1da1b2828342a54" redirectURL:@"http://app.haomaijiankang.com/weibo"];
}
    

//MARK: 分享网页地址
+(void)shareWebUrl:(NSString *)url icon:(NSString *)icon title:(NSString *)title desc:(NSString *)desc{
    [UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_WechatSession),@(UMSocialPlatformType_WechatTimeLine),@(UMSocialPlatformType_QQ)]];
    [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
        // 根据获取的platformType确定所选平台进行下一步操作
        [self shareWebPageToPlatformType:platformType WebUrl:url icon:icon title:title desc:desc];
    }];
}

    
+(void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType WebUrl:(NSString *)url icon:(NSString *)icon title:(NSString *)title desc:(NSString *)desc{
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    //创建网页内容对象
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:desc thumImage:icon];
    //设置网页地址
    shareObject.webpageUrl =url;
    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:nil completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
        }else{
            NSLog(@"response data is %@",data);
        }
    }];
}
    
    
//MARK: 分享图片
+(void)sharePicture:(UIImage *)picture text:(NSString *)text{
    [UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_WechatSession),@(UMSocialPlatformType_WechatTimeLine),@(UMSocialPlatformType_QQ),@(UMSocialPlatformType_Sina)]];
    [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
        // 根据获取的platformType确定所选平台进行下一步操作
        NSLog(@"platformType==%ld userInfo==%@",platformType,userInfo);
        [self shareImageAndTextToPlatformType:platformType picture:picture text:text];
    }];
}
+(void)shareImageAndTextToPlatformType:(UMSocialPlatformType)platformType picture:(UIImage *)picture text:(NSString *)text{
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    //设置文本
    messageObject.text =text;
    //创建图片内容对象
    UMShareImageObject *shareObject = [[UMShareImageObject alloc] init];
    //如果有缩略图，则设置缩略图
    [shareObject setShareImage:picture];
    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:nil completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
        }else{
            NSLog(@"response data is %@",data);
        }
    }];
}


// MARK: 是否安装qq
+(BOOL)isInstallQQ{
   return [[UMSocialManager defaultManager]isInstall:UMSocialPlatformType_QQ];
}

// MARK: 是否安装微信
+(BOOL)isInstallWechat{
    return [[UMSocialManager defaultManager]isInstall:UMSocialPlatformType_WechatSession];
}

// MARK: 是否安装新浪
+(BOOL)isInstallSina{
    return [[UMSocialManager defaultManager]isInstall:UMSocialPlatformType_Sina];
}


@end
